//
//  QZStarViewCell.m
//  WeiWeiHaircut
//
//  Created by apple on 15/12/18.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZStarViewCell.h"


@interface QZStarViewCell ()
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UIImageView *star1;
@property (weak, nonatomic) IBOutlet UIImageView *star2;
@property (weak, nonatomic) IBOutlet UIImageView *star3;
@property (weak, nonatomic) IBOutlet UIImageView *star4;
@property (weak, nonatomic) IBOutlet UIImageView *star5;


@end
@implementation QZStarViewCell

- (void)awakeFromNib {
    _star1.tag = 100 +1;
    _star2.tag = 100 +2;
    _star3.tag = 100 +3;
    _star4.tag = 100 +4;
    _star5.tag = 100 +5;
 
    
    int i = 1;
    for (UIImageView *view in _bgView.subviews) {
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick:)];
        view.userInteractionEnabled = YES;
        
        [view addGestureRecognizer:tap];
       
        i++;
    }
}


- (void)imageClick:(UITapGestureRecognizer *)tap{
    NSInteger index = tap.view.tag - 100;
//   
//    for (UIImageView*imageView in _bgView.subviews){
//        if (imageView.tag-100 <= index) {
//            imageView.image = [UIImage imageNamed:@"icon_star"];
//            
//        }else{
//            imageView.image = [UIImage imageNamed:@"icon_star2"];
//        }
//    }
    self.starNumber = index;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setStarNumber:(NSInteger)starNumber{
    
    _starNumber = starNumber;
//    if (starNumber) {
//        _commitLabel.text = @"已评价";
//        _bgView.userInteractionEnabled = NO;
//    }else{
//        _commitLabel.text = @"请对本次服务评价";
//        _bgView.userInteractionEnabled = YES;
//    }
    for (UIImageView*imageView in _bgView.subviews){
        if (imageView.tag-100 <= starNumber) {
            imageView.image = [UIImage imageNamed:@"icon_star"];
            
        }else{
            imageView.image = [UIImage imageNamed:@"icon_star2"];
        }
    }
}
@end
